package com.app.buss.ui;

import android.os.Bundle;
import android.widget.TextView;

import com.app.buss.R;
import com.app.buss.base.BaseActivity;
import com.app.buss.bean.MarketBean;
import com.app.buss.mvp.presenter.MainPresenter;
import com.app.buss.mvp.view.IMainView;
import com.vinsonguo.klinelib.chart.TimeLineView;
import com.vinsonguo.klinelib.model.HisData;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MaketDetailActivity extends BaseActivity<MainPresenter> implements IMainView {


    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.tv_add_num)
    TextView tvAddNum;
    @BindView(R.id.tv_add_rate)
    TextView tvAddRate;
    @BindView(R.id.tv_high_num)
    TextView tvHighNum;
    @BindView(R.id.tv_low_num)
    TextView tvLowNum;
    @BindView(R.id.timeline)
    TimeLineView timeline;
    private  MarketBean bean;

    @Override
    protected MainPresenter createPresenter() {
        return new MainPresenter(this);
    }

    @Override
    protected int bindContent() {
        return R.layout.aty_market_detail;
    }

    @Override
    protected void initSome() {
        if(getIntent().getExtras()!=null){
          bean = (MarketBean) getIntent().getExtras().getSerializable("data");
        }
        if(bean!=null) {
            initToolBar(bean.getPair());
            tvNum.setText(bean.getBuy());
            tvHighNum.setText(bean.getBuy());
            tvLowNum.setText(bean.getSell());
            if(bean.getSignal().equals("Buy")){
                tvNum.setTextColor(getResources().getColor(R.color.green));
                tvAddNum.setText("+0.0013");
                tvAddNum.setTextColor(getResources().getColor(R.color.green));
                tvAddRate.setTextColor(getResources().getColor(R.color.green));
                tvAddRate.setText("+0.01%");
            }else {
                tvNum.setTextColor(getResources().getColor(R.color.red));
                tvAddNum.setText("-0.0021");
                tvAddNum.setTextColor(getResources().getColor(R.color.red));
                tvAddRate.setTextColor(getResources().getColor(R.color.red));
                tvAddRate.setText("-0.02%");
            }
        }
        List<HisData> hisDatas = new ArrayList<>();
        hisDatas.add(new HisData(Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),
                Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),1000000,getMillisNextEarlyMorning(8)));
        hisDatas.add(new HisData(Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),
                Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),1000000,getMillisNextEarlyMorning(9)));
        hisDatas.add(new HisData(Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),
                Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),1000000,getMillisNextEarlyMorning(10)));
        hisDatas.add(new HisData(Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),
                Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),1000000,getMillisNextEarlyMorning(11)));
        hisDatas.add(new HisData(Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),
                Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),1000000,getMillisNextEarlyMorning(12)));
        hisDatas.add(new HisData(Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),
                Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),1000000,getMillisNextEarlyMorning(13)));
        hisDatas.add(new HisData(Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),
                Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),1000000,getMillisNextEarlyMorning(14)));
        hisDatas.add(new HisData(Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),
                Double.parseDouble(bean.getBuy()),Double.parseDouble(bean.getSell()),1000000,getMillisNextEarlyMorning(15)));
        timeline.setDateFormat("HH:mm");
        timeline.setLastClose(hisDatas.get(0).getClose());
        timeline.initData(hisDatas);
    }

    @Override
    public void getDataSuccess(Object model) {
    }

    @Override
    public void getDataFail(String msg) {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    private Long getMillisNextEarlyMorning(int i) {
        Calendar cal = Calendar.getInstance();
        //日期加1
        cal.add(Calendar.DAY_OF_YEAR, -1);
        //时间设定到8点整
        cal.set(Calendar.HOUR_OF_DAY, i);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTimeInMillis();
    }
}
